package com.yao.mybatis.utils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.io.Reader;

/**
 * 讲流解析成document
 * @author Administrator
 */
public class DocumentUtils {
    /**
     * 解析字节流
     * @param in
     * @return
     */
    public static Document readFileAsDocument(InputStream in){
        SAXReader reader = new SAXReader();
        try {
            return reader.read(in);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * parse reader
     * @param in
     * @return
     */
    public static Document readFileAsDocument(Reader in){
        SAXReader reader = new SAXReader();
        try {
            return reader.read(in);
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        return null;
    }
}
